package com.fh.fruit.service.activity.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.fruit.service.activity.ActivityGoldBowlManager;
import com.fh.util.DateUtil;
import com.fh.util.PageData;

/**
 * 金饭碗活动 service
 * 
 * @author Administrator
 * @version 2017.11.30 15:39
 */
@Service("goldBowlService")
public class ActivityGoldBowlService implements ActivityGoldBowlManager {
	@Resource(name = "daoSupport")
	private DaoSupport dao;

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getListActivity(Page page) throws Exception {
		PageData pd =page.getPd();
		String endTime=pd.getString("endTime");
			if(endTime != null && !"".equals(endTime)){
				pd.put("endTime", DateUtil.getSpecifiedDayBefore(pd.getString("endTime")));
				page.setPd(pd);
			}
		return (List<Map<String, Object>>) dao.findForList("ActivityGBManager.getActivitylistPage", page);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getListWorkOff(Page page) throws Exception {
		PageData pd =page.getPd();
		String endTime=pd.getString("endTime");
			if(endTime != null && !"".equals(endTime)){
				pd.put("endTime", DateUtil.getSpecifiedDayBefore(pd.getString("endTime")));
				page.setPd(pd);
			}
		return (List<Map<String, Object>>) dao.findForList("ActivityGBManager.getWorkOfflistPage", page);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getGoldBowInfo(PageData pd) throws Exception {
		Map<String,Object> map= new HashMap<>();
		 map=(Map<String,Object>) dao.findForObject("ActivityGBManager.getGoldBowInfo", pd);
		 Map<String,Object> map1=(Map<String,Object>) dao.findForObject("ActivityGBManager.getGoldBowInfo2", pd);
		 if(map != null){
			 if(map1 !=null){
				 map.put("pNum", map1.get("pNum"));
			 }
		 }
		 return map;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getGoldBowGoodsInfo(PageData pd) throws Exception {
		List<Map<String, Object>> res=null;
		Map<String,Object> m= new HashMap<>();
		 res=(List<Map<String, Object>>) dao.findForList("ActivityGBManager.getGoldBowGoodsInfo", pd);
		 for (Map<String, Object> map : res) {
			 map.put("startTime", pd.getString("startTime"));
			 map.put("endTime", pd.getString("endTime"));
			m=(Map<String,Object>) dao.findForObject("ActivityGBManager.getGoldBowInfo1", map);
			if(m!= null){
				map.put("num", m.get("num"));
				map.put("price", m.get("price"));
			}else{
				map.put("num", 0);
				map.put("price", 0);
			}
		}
		 return res;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getGoldBowNum(PageData pd) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		List<Map<String, Object>> listNum=(List<Map<String, Object>>) dao.findForList("ActivityGBManager.getGoldBowNum", pd);
		int a=0;int b=0;int c=0;int d=0;int e=0;int f=0;int g=0;int z=0;
		for (Map<String, Object> m : listNum) {
			Long num=(Long)m.get("num");
			if(num>=10){
				a++;
			} else if(num >=50){
				b++;
			} else if(num >=100){
				c++;
			} else if(num >=500){
				d++;
			} else if(num >=1000){
				e++;
			} else if(num >=5000){
				f++;
			} else if(num >=10000){
				g++;
			} else if(num < 10){
				z++;
			}
		}
		map.put("a", a);map.put("b", b);map.put("c", c);map.put("d", d);map.put("e", e);map.put("f", f);map.put("g", g);map.put("z", z);
		return map;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getProfitActivity(Page page) throws Exception {
		PageData pd =page.getPd();
		String endTime=pd.getString("endTime");
			if(endTime != null && !"".equals(endTime)){
				pd.put("endTime", DateUtil.getSpecifiedDayBefore(pd.getString("endTime")));
				page.setPd(pd);
			}
		return (List<Map<String, Object>>) dao.findForList("ActivityGBManager.getProfitlistPage", page);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> getProfitDetails(PageData pd) throws Exception {
		return (Map<String,Object>) dao.findForObject("ActivityGBManager.getProfitDetails", pd);
	}

}
